package com.yatush.testmodule.web;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;

import springapp.service.PriceIncrease;
import springapp.service.ProductManager;

import com.yatush.backstage.web.BaseAction;
import com.yatush.backstage.web.Bean;

public class ToDoAction extends BaseAction {

	@Autowired
    private ProductManager productManager;
		
	@Override
	protected Bean loadData(HttpServletRequest request) {
		ToDoBean bean = new ToDoBean();
		bean.setPercentage(20);
        return bean;
	}

	@Override
	protected String saveForm(Bean bean) {
		ToDoBean todoBean = (ToDoBean) bean;
		int increase = todoBean.getPercentage();
        logger.info("Increasing prices by " + increase + "%. Using ToDoAction!!");
        productManager.increasePrice(increase);

        logger.info("returning from PriceIncreaseForm view to " + getSuccessView());

        return getSuccessView();
	}

}
